//! API数据模型
//! 
//! 定义HTTP API的请求和响应数据结构

use serde::{Serialize, Deserialize};
use crate::types::*;

/// 创建沙箱请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateSandboxRequest {
    /// 沙箱规格
    pub spec: SandboxSpec,
    /// 可选的标签
    pub labels: Option<std::collections::HashMap<String, String>>,
}

/// 创建沙箱响应
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateSandboxResponse {
    /// 沙箱ID
    pub sandbox_id: SandboxId,
    /// 状态
    pub status: String,
    /// 消息
    pub message: String,
}

/// 沙箱信息响应
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SandboxInfoResponse {
    /// 沙箱ID
    pub sandbox_id: SandboxId,
    /// 状态
    pub status: String,
    /// 创建时间
    pub created_at: String,
    /// 语言
    pub language: Language,
    /// 元数据
    pub metadata: Option<SandboxMetadata>,
}

/// 系统统计响应
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemStatsResponse {
    /// 总沙箱数
    pub total_sandboxes: usize,
    /// 活跃沙箱数
    pub active_sandboxes: usize,
    /// 池统计
    pub pool_stats: PoolStatsCollection,
    /// 内存使用率
    pub memory_usage: String,
    /// CPU使用率
    pub cpu_usage: String,
}

/// 池统计集合
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PoolStatsCollection {
    /// 热池统计
    pub hot_pool: PoolStats,
    /// 温池统计
    pub warm_pool: PoolStats,
    /// 冷池统计
    pub cold_pool: PoolStats,
}

/// 健康检查响应
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthResponse {
    /// 状态
    pub status: String,
    /// 版本
    pub version: String,
    /// 时间戳
    pub timestamp: String,
}

/// 错误响应
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErrorResponse {
    /// 错误码
    pub error_code: String,
    /// 错误消息
    pub error_message: String,
    /// 时间戳
    pub timestamp: String,
}

impl ErrorResponse {
    /// 创建错误响应
    pub fn new(error_code: String, error_message: String) -> Self {
        Self {
            error_code,
            error_message,
            timestamp: chrono::Utc::now().to_rfc3339(),
        }
    }
}